package gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Line2D;
import java.util.ArrayList;
import javax.swing.*;


import environment.World;

import boids.predators.Predator;
import boids.preys.Prey;

import util.Vector;



public class TestComponent extends JComponent
{	
	private final World world;
	
	public TestComponent(final World world)
	{
		this.world = world;
		this.setFocusable(true);
		
		addMouseListener(new MouseAdapter()
		{
			public void mouseClicked(MouseEvent e)
			{
				world.updatePredator(new Vector(e.getX(), e.getY()));				
				
			}
		});
		
		addKeyListener(new KeyAdapter()
		{
			public void keyPressed(KeyEvent e)
			{
				int keyCode = e.getKeyCode();
				
				switch(keyCode)
				{
					case KeyEvent.VK_LEFT: world.manualPredatorUpdate(new Vector(-1, 0)); break;
					case KeyEvent.VK_RIGHT: world.manualPredatorUpdate(new Vector(1, 0)); break;
					case KeyEvent.VK_UP: world.manualPredatorUpdate(new Vector(0, -1)); break;
					case KeyEvent.VK_DOWN: world.manualPredatorUpdate(new Vector(0, 1)); break;
				}
			}
		});
	}
	
	public void paintComponent(Graphics g)
	{
		Graphics2D g2 = (Graphics2D) g;
		
		for (Prey boid : world.getBoids())
		{
			boid.draw(g2);

		}
		
		for (Predator predator : world.getPredators())
		{
			predator.draw(g2);
		}
	}
}
